#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "sb.h"

StringBuilder *sb_new()
{
    StringBuilder *sb =  (StringBuilder*) calloc(sizeof(StringBuilder), 1);
    sb->length = 0;
    return sb;
}

void sb_free(StringBuilder *sb)
{
    if(sb) {
        sb->length = 0;
        //if(sb->str) free(sb->str);
        free(sb);
    }
}

int sb_append(StringBuilder *sb, const char *s)
{
    int length = 0;
    if(sb == NULL) return -1;

    if(NULL == s || '\0' == *s)
        return sb->length;

    length = strlen(s);
    sb->length += length;

    return sb->length;
}
